home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 10
/
The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso
/
PC_SIGCD
/
26
/
3
/
DISK2631.ZIP
/
EXISTS.ZIP
/
EXISTS.BAS
< prev
next >
Wrap
BASIC Source File
|
1990-02-14
|
5KB
|
138 lines
$COMPILE UNIT 'make a unit
' TB - bug fixes 7/4/88 originally made 3-27-88
' PB Version 1/25/90 2/14/90
' To compile in the IDE, simply Alt-F9
' to compile from the command line,
' PBC EXISTS -CU
' note: to use the debugger, you must compile from the IDE
' as no debugging action is passed from the PBC.
%False = 0
%True = NOT %False
EXTERNAL MatchedFil$'make it global
' the following sub, made PUBLIC, allows the main to access it
SUB FindVol(Filename$,FileErr%,CreateDate$,CreatTime$) PUBLIC
MatchedFil$ = ""
'set up DTA 'Barry Erick 75300,214 , B.ERICK
REG 1, &H2F00 'get DOS's dta
CALL INTERRUPT &H21 ' to find returned file info
DTASegment& = REG(9) 'es
DTAOffset& = REG(2) 'bx
FExist$ = Filename$+CHR$(0) ' make it a ASCIIZ string for DOS
' Note the StrPtr and StrSeg. This is the major change
' from a TB program. In TB, we would :
' Def Seg
' StrSeg& = PEEK(1)*256+PEEK(0) ' Find TB's String Segment
' DEF SEG = VARSEG(FExist$) ' Look for pointer
' StringSegPtr& = VARPTR(FExist$)' Point to TB's string Segment
' StringSegOffset& = PEEK(StringSegPtr&+2)+256 * PEEK(StringSegPtr&+3)
' DEF SEG ' Restore Default Segment
' REG 8,StrSeg& ' String Segment to Reg DS
' REG 4,StringSegOffset&' String Seg Offset to Reg DX
' REG 3,&H7 ' Find all matching files Attribute
' REG 1,&H4E00 ' DOS Function Find First Match
' CALL INTERRUPT &H21 ' Just look for first matching file
' FileErr% = REG(1) ' Reg AX.. 0 = no error
' DEF SEG = DTASegment&
' But because of PB's unlimited string space, we do it this way:
REG 8,StrSeg(FEXIST$)' String Segment to Reg DS
REG 4,StrPTR(FEXIST$)' String Seg Offset to Reg DX
' The rest is the same as a TB program, but MUCH faster
REG 3,&H23 ' Find all matching files 'cept vol or dir
REG 1,&H4E00 ' DOS Function Find First Match
CALL INTERRUPT &H21 ' Just look for first matching file
FileErr% = REG(1) ' Reg AX.. 0 = no error
DEF SEG = DTASegment& 'point to the DTA
' Get the creation date that dos just stuck in the dta
FOR X = 1 TO 11
IF PEEK(DTAOffset&+x)=0 THEN EXIT FOR'none found
MatchedFil$=Matchedfil$+CHR$(PEEK(dtaOffset& + x))
NEXT
IF LEFT$(MatchedFil$,1) <> CHR$(&H13) THEN
MatchedFil$=LEFT$(MatchedFil$,8)+"."+RIGHT$(MatchedFil$,3)
END IF
d1! = PEEK(23+DTAOffset&)
d2! = PEEK(22+DTAOffset&)
CreateDate& = PEEK(25+DTAOffset&)*256+PEEK(24+DTAOffset&)
creattime& = d1*256
INCR creattime&,d2
' now start tearing apart the words returned
hour% = INT(CreatTime&/2048)
hours% = hour%
IF hour% >12 THEN 'returned in 24 hour time, make 12 hour time
DECR hours%,12
pm% = %true
ELSE
pm% = %False
END IF
hour$ = MID$(STR$(hours%),2)'strip leading space
minutes% = (CreatTime&-(CLNG(hour%)*2048))\32
minutes$ = MID$(STR$(minutes%),2)' strip leading space
IF LEN(minutes$)=1 THEN minutes$="0"+minutes$
Year% = CreateDate&\512
Year$ = MID$(STR$(Year%+1980),2)' minimum dos date is 1/1/1980
Month% = (CreateDate&-(Year%*512))\32
Month$ = MID$(STR$(Month%),2)
Day$ = MID$(STR$(CreateDate& MOD 32),2)
IF LEN(day$)= 1 THEN day$= "0"+day$
IF FileErr% = 0 THEN
CreateDate$ = Month$+"-"+Day$+"-"+Year$
CreatTime$ = Hour$+":"+MINUTES$
IF pm% THEN
CreatTime$ = CreatTime$+" pm"
ELSE
CreatTime$ = CreatTime$+" am"
END IF
ELSE
CreatTime$ = ""
CreateDate$ = ""
END IF
DEF SEG
END SUB
' The next item is made available to outside the UNIT
FUNCTION FileExist%(Filename$) PUBLIC
CALL FINDVOL(FileName$,Ferr%,a$,b$)
SELECT CASE Ferr%
CASE 0
FileExist% = %True
CASE ELSE
FILEEXIST% = 0
END SELECT
END FUNCTION
' The following is a demo
' The Sub does not require a DEFINT A-Z, as all variables are labeled.
' CLS
' LINE INPUT "Which filename do you need to check ";filename$
' CALL FindVol(Filename$,FileErr%,CreateDate$,CreatTime$)
' SELECT CASE FileErr%
' CASE 0
' PRINT "I found ";UCASE$(filename$)
' PRINT "Created ";CreateDate$;
' PRINT " at ";CreatTime$
' CASE 2,18
' PRINT "No File Found."
' END SELECT
' END (FileErr%)
' IF FileExist%(filename$) then
' print "I found ";filename$
' END(0)
' else
' print "NotFound
' END(53)
' end if